import { s_getcommontableinfoBycondition, s_updateInfo } from "@/services/basis";
import { ProCard, ProForm } from "@ant-design/pro-components";
import { Button, Card, Col, GetProp, List, message, Row, Upload, UploadProps,Image, Space, Modal } from "antd";
import { useState } from "react";

const App:React.FC<{source:string,x_id:number,tdata:any,operater_id:any}>=(props)=>{
    //参数1：source_xid,setData：主调useState函数回传,type:1查看，2编辑，fdata:如下
   // 参数2：fdata:源表source_table,源source_id,源字段source_field,源单据号/编号source_code,源值source_value
    //注意：source_table需以addition_为前缀
    // 操作类型（1查看或2编辑）type
    // 为方便，仅支持图片和PDF两种类型
    //--------------------------------------新：直接显示附件界面，取消原来的按钮显示。其他不变-------------2025-02-10--------
   //  const {source_table,source_id,source_field,source_value,source_code}=props.fdata;
    const {x_id,operater_id,source,tdata}=props;
   //  const {ftype}=props.fdata;
 
     //限制上传文件类型
     type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0];
     const beforeUpload = (file: FileType) => {
         const  sufix=file.name.substring(file.name.indexOf('.')+1);
         const isPicture = sufix === 'JPG' || sufix === 'jpg'|| sufix === 'jpeg'|| sufix === 'JPEG'
                                || sufix === 'PNG'|| sufix === 'png'|| sufix === 'bmp'|| sufix === 'BMP';
         if (!isPicture) {
              message.error('错误！只可以导入图像文件文件!');
         }
         const isLt2M = file.size / 1024 / 1024;
         if (!isLt2M) {
              message.error('错误！要导入的文件必须小于1MB!');
         }
         return  isPicture&&isLt2M;
         };
    
         return (<>
{/*  
            <ProCard title='导入数据' style={{height:600}}>
            <ProForm submitter={false} style={{height:550}}  layout="horizontal" 
                     labelAlign="left" labelCol={{offset:0,span:5}}> */}
                            <Upload
                                       name='upfile'
                                       action='/basis_api/upload/file/htoms2/images'
                                       beforeUpload={beforeUpload}
                                       data={{x_id,operater_id,source,tdata:tdata.data}}
                                       onChange={(info)=>{
                                            if(info.file.status=='done'){
                                                 message.success('文件上传成功！')
                                               
                                              };
                                            if(info.file.status=='error')
                                                 message.error('文件上传失败'+info.file.error);
                                              }}
                                          >
                                              {/* {JSON.stringify(source_code)} */}
                                              <Button style={{width:100}}  >
                                                   上传商品图</Button>
                                     </Upload>
                                      
                                   {/* {itemList} */}
                                 
                           {/* </ProForm>
                           </ProCard> */}
                     {/* </Modal> */}
         </>);
}

export default App;